<template>
  <div>
    <el-dialog
      title="审核"
      :visible.sync="dialogVisible"
      width="600px"
      @closed="resetForm('form')"
    >
      <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="120px">
          <el-form-item label="审核" prop="audit">
            <el-radio-group v-model="form.auditStatus">
              <el-radio label="2">通过</el-radio>
              <el-radio label="3">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="form.resultDes"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button  type="custom" v-preventReClick  @click="submitForm('form')">提 交</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { sysCourseStudentUpdate } from "@/api/admin/courseLibrary/sysCourseStudent.js";
import Bus from "@/utils/bus.js";
export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        id: "",
        auditStatus: "2", //成员审核状态：1-待审核，2-审核通过，3-不通过
        resultDes: "",
      },
      rules: {
        audit: [{ required: true, message: "请审核", trigger: "blur" }],
      },
    };
  },
  mounted() {
    Bus.$on("showDialogCourseTeamAudit", (v) => {
      this.form.id = v.id;
      this.dialogVisible = true;
    });
  },
  beforeDestroy() {
    Bus.$off("showDialogCourseTeamAudit");
  },
  methods: {
    submitForm() {
      if (this.form.auditStatus == 3 && this.form.resultDes == "") {
        this.$message.error("请说明不通过原因");
        return;
      }
      this.audit();
    },
    //审核
    audit() {
      sysCourseStudentUpdate(this.form).then((res) => {
        if (res.data.code == 0) {
          this.dialogVisible = false;
          Bus.$emit("refreshCourseTeam");
          this.$message({
            message: "操作成功",
            type: "success",
          });
        }
      });
    },
    //重置表单
    resetForm(form) {
      this.$refs[form].resetFields();
      this.form.resultDes = "";
      this.form.auditStatus = "2";
    },
  },
};
</script>